package com.example.file_management.controller;

import com.example.file_management.pojo.user.Auth;
import com.example.file_management.pojo.user.Group;
import com.example.file_management.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/groupsname")
@CrossOrigin(origins = "http://localhost:5173")
public class GroupController {

    @Autowired
    private GroupService groupService;

    // 获取所有组
    @GetMapping
    public List<Group> getAllGroups() {
        return groupService.getAllGroups();
    }

    @GetMapping("/{id}/users")
    public List<Auth> getUsersByGroupId(@PathVariable Long id) {
        return groupService.getUsersByGroupId(id);
    }
    // 创建组
    @PostMapping
    public String createGroup(@RequestBody Group group) {
        return groupService.createGroup(group);
    }

    // 更新组
    @PutMapping("/{id}")
    public String updateGroup(@PathVariable Long id, @RequestBody Group group) {
        group.setGroupId(id);
        return groupService.updateGroup(group);
    }
    //根据角色id获取组名
//    @GetMapping("/role/{roleId}")
//    public List<Group> getGroupsByRoleId(@PathVariable Long roleId) {
//        return groupService.getGroupsByRoleId(roleId);
//    }
    // 删除组
    @DeleteMapping("/{id}")
    public String deleteGroup(@PathVariable Long id) {
        return groupService.deleteGroup(id);
    }
}
